package core

import (
	"log"
	"os"
	"os/signal"
	"syscall"
)

func SignalNotify(c chan bool) {
	ch := make(chan os.Signal)
	signal.Notify(ch, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGKILL)
	for {
		sig := <-ch
		switch sig {
		case syscall.SIGHUP, syscall.SIGKILL, syscall.SIGTERM:
			log.Println("[ OS][ TERM] - program has exit !")
			dispose()
			close(c)
		}
	}
}

func dispose() {
	GetRedisPool().Close()
	msq.Close()
}
